﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataAchive.Base;
using LiveCharts;

namespace DataAchive.Model.ViewModels
{
    public class StatisticsViViewModel : ViewModelBase
    {
        /// <summary>
        /// 异常优先级
        /// </summary>
        public ObservableCollection<string> ClassIfyPriorityArray

        {
            get { return _classIfyPriorityArray; }
            set { _classIfyPriorityArray = value; OnPropertyChanged(nameof(ClassIfyPriorityArray)); }
        }

        private ObservableCollection<string> _classIfyPriorityArray = new ObservableCollection<string> {
                                                     "鱼叉处露白",
                                                     "焊点处露白",
                                                     "焊带偏移",
                                                     "焊带缺失",
                                                     "搭条",
                                                     "电池片崩边缺角",
                                                     "电池片划伤",
                                                     "电池片破片",
                                                     " 电池片异物",
                                                     " 汇流条缺失",
                                                     " 汇流条歪斜",
                                                     " 汇流条焊带缺失",
                                                     " 电池片脏污",
                                                     " 电池片背景",
                                                     " 组件串错位",
                                                     " 组件片间距异常",
                                                     " 组件边缘异物",
                                                     " 组件边缘脏污",
                                                     " 组件边缘划伤",
                                                     " 组件条形码歪斜",
                                                     " 组件条形码缺失",
                                                     " 组件边缘背景",
                                                     " 间距不良",                                                     
                                                     " RIBBON_DLB",



                                                };



        /// <summary>
        /// 饼图数据源
        /// </summary>
        public SeriesCollection PicCharData
        {
            get { return _picCharData; }
            set
            {
                _picCharData = value;
                OnPropertyChanged(nameof(PicCharData));

            }
        }
        private SeriesCollection _picCharData = new SeriesCollection();

        /// <summary>
        /// 柱状图数据源
        /// </summary>
        public SeriesCollection CartesianCharData
        {
            get { return _cartesianCharData; }
            set
            {
                _cartesianCharData = value;
                OnPropertyChanged(nameof(CartesianCharData));

            }
        }
        private SeriesCollection _cartesianCharData = new SeriesCollection();

        /// <summary>
        /// 柱状图的X坐标值
        /// </summary>
        public List<string> CartesianCharX
        {
            get { return _cartesianCharX; }
            set
            {
                _cartesianCharX = value;
                OnPropertyChanged(nameof(CartesianCharX));
            }
        }
        private List<string> _cartesianCharX = new List<string>();
        /// <summary>
        /// 柱状图的Y坐标值
        /// </summary>  
        public List<int> CartesianCharY
        {
            get { return _cartesianCharY; }
            set
            {
                _cartesianCharY = value;
                OnPropertyChanged(nameof(CartesianCharY));

            }
        }
        private List<int> _cartesianCharY = new List<int>();


        /// <summary>
        /// 统计绑定的数据源
        /// </summary>
        public Page<ObservableCollection<dynamic>> StatisticsListData
        {
            get { return _statisticsListData; }
            set
            {
                _statisticsListData = value;
                OnPropertyChanged(nameof(StatisticsListData));

            }
        }
        public Page<ObservableCollection<dynamic>> _statisticsListData = new Page<ObservableCollection<dynamic>>();
        /// <summary>
        /// 月度统计绑定的数据源
        /// </summary>
        public ObservableCollection<dynamic> MonthStatisticsListData
        {
            get { return _monthStatisticsListData; }
            set
            {
                _monthStatisticsListData = value;
                OnPropertyChanged(nameof(MonthStatisticsListData));

            }
        }
        public ObservableCollection<dynamic> _monthStatisticsListData = new ObservableCollection<dynamic>();

        private DateTime _startTime = DateTime.Now.AddDays(-1);

        public DateTime StartTime
        {
            get { return _startTime; }
            set
            {
                _startTime = value;
                OnPropertyChanged(nameof(StartTime));

            }
        }
        private DateTime _endTime = DateTime.Now;

        public DateTime EndTime
        {
            get { return _endTime; }
            set
            {
                _endTime = value;
                OnPropertyChanged(nameof(EndTime));

            }
        }
        private DateTime _monthTime = DateTime.Now;
        public DateTime MonthTime
        {
            get { return _monthTime; }
            set
            {
                _monthTime = value;
                OnPropertyChanged(nameof(MonthTime));

            }
        }
        /// <summary>
        /// OK数量
        /// </summary>
        public int OKNum
        {
            get { return _okNum; }
            set
            {
                _okNum = value;
                OnPropertyChanged(nameof(OKNum));
                UpdateAmount();
                UpdateYield();
            }
        }
        private int _okNum = 0;
        /// <summary>
        /// NG数量
        /// </summary>
        public int NGNum
        {
            get { return _ngNum; }
            set
            {
                _ngNum = value;
                OnPropertyChanged(nameof(NGNum));
                UpdateAmount();
                UpdateYield();
            }
        }
        private int _ngNum = 0;
        /// <summary>
        /// 总数
        /// </summary>
        public int Amount
        {
            get { return _amount; }
            set
            {
                _amount = value;
                OnPropertyChanged(nameof(Amount));
            }
        }
        private int _amount = 0;
        /// <summary>
        /// 优率
        /// </summary>
        public string Yield
        {
            get { return _yield; }
            set
            {
                _yield = value;
                OnPropertyChanged(nameof(Yield));
            }
        }
        private string _yield = "0.00%";

        private List<StatisticsClassifyModel> _classIfyList = new List<StatisticsClassifyModel>();
        public List<StatisticsClassifyModel> ClassIfyList
        {
            get { return _classIfyList; }
            set
            {
                _classIfyList = value;
                OnPropertyChanged(nameof(ClassIfyList));
            }

        }


        private List<StatisticsClassifyModel> _allDataList = new List<StatisticsClassifyModel>();
        public List<StatisticsClassifyModel> AllDataList
        {
            get { return _allDataList; }
            set
            {
                _allDataList = value;
                OnPropertyChanged(nameof(AllDataList));
            }

        }


        /// <summary>
        /// 更新总数
        /// </summary>
        private void UpdateAmount()
        {
            Amount = OKNum + NGNum;
        }

        /// <summary>
        /// 更新优率
        /// </summary>
        private void UpdateYield()
        {
            if (Amount <= 0)
                Yield = "0.00%";
            else
                Yield = Math.Round(((decimal)OKNum / Amount) * 100, 2).ToString("0.00") + "%";

            //Math.Round(((decimal)OKNum / ((OKNum + NGNum) <= 0 ? 1 : (OKNum + NGNum))) * 100, 2) + "%";
        }

    }




}
